﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using libDAL;

namespace libAddressBook.BUS
{

    public sealed class clsBUSInterfaceCompanyHistory
    {
        private clsBUSCustomerHistory _BUSHistory;
        private string strCompanyHistoryID = string.Empty;
        private string strCompanyID = string.Empty;
        //private DataSet dsHistory;
        //private DataTable dtTempHistory;
        private cls_DAL _DAL;

        public clsBUSInterfaceCompanyHistory()
        {
            _BUSHistory = new clsBUSCustomerHistory(); 
        }

        public bool get_checkHistoryRows()
        {
            bool bolStatus = false;
            try
            {
             bolStatus =  _BUSHistory.get_CheckCompanyHistoryExists();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_checkHistoryRows"); 
            }

            return bolStatus;
        }

        public bool get_Records(string strHistoryID)
        {
            bool bolStatus = false;
            try
            {

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_Records"); 
            }
            return bolStatus;
        }

        //gets all the history of each branches
        public bool set_Records(string strCompanyID)
        {
            bool bolStatus = false;
            try
            {
                //gets all the history of each branches
                if (_BUSHistory.set_Records(strCompanyID) == true)
                {
                    bolStatus = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_Records"); 
            }
            return bolStatus;
        }

        public bool set_NewCompanyHistory()
        {
            return _BUSHistory.set_NewCompanyHistory();
        }
        //get_CurrentRowSelectedDetails()
        public bool set_UpdateCustomerHistory(DataRow drUpdate)
        {
            bool bolStatus = false;
            try
            {
                bolStatus = _BUSHistory.set_UpdateCustomerHistory(drUpdate); 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_UpdateCustomerHistory"); 
            }
            return bolStatus;
        }
        public bool set_UpdateHistory()
        {
            bool bolStatus = false;
            try
            {
                //if (_BUSHistory.set_UpdateCustomerHistory() == true)
                //{
                //    bolStatus = true;
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_UpdateHistory"); 
            }
            return bolStatus;
        }

        public bool set_SpecificCopanyDetails(string strCompanyHistoryID, DataRow drDetails)
        {
            bool bolStatus = false;
            try
            {
                if (_BUSHistory.set_SpecificCopanyDetails(strCompanyHistoryID, drDetails) == true)
                {
                    bolStatus = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_SpecificCopanyDetails"); 
            }
            return bolStatus;
        }

        public DataTable get_CompanyAllHistory
        {
            get
            {
                return _BUSHistory.get_CompanyAllHistory;
            }
        }

        public DataTable get_CompanyHistory(string strCompanyID)
        {
            DataTable dt = new DataTable();

            return _BUSHistory.get_CompanyHistory(strCompanyID);
        }

        public cls_DAL get_DAL
        {
            get
            {
               return _BUSHistory.get_DAL; 
            }
        }

        public bool set_InsertNewRow(DataRow drInsert)
        {
            bool bolStatus = false;
            try
            {
                if (_BUSHistory.set_InsertNewRow(drInsert) == true)
                {
                    bolStatus = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_InsertNewRow");
            }
            return bolStatus;
        }

        public bool set_Default(string strcompanyHistoryID, int intType)
        {
            bool bolStatus = false;
            try
            {
                _BUSHistory.set_Default(strcompanyHistoryID, intType);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_Default"); 
            }

            return bolStatus;
        }

        public bool AddNewRowHistory(DataRow drInsert)
        {
             bool bolStatus = false;
             try
             {
                 if (_BUSHistory.set_InsertNewRow(drInsert) == true)
                 {
                     bolStatus = true;
                 }
             }
             catch (Exception ex)
             { 
                
             }
             return bolStatus; 
        }

        public void set_RejectChanges()
        {
            try
            {
                //if (dsHistory != null)
                //{
                //    dsHistory.RejectChanges();
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_RejectChanges"); 
            }
        }

        internal void setInitializeHistory()
        {
            _BUSHistory.set_InitializeHistory();
            //throw new NotImplementedException();
        }
    }

    public sealed class clsUsersMainBUSInterface : IDisposable 
    {
        private clsMainBUS _BUS;
        private string strCompanyID =  string.Empty;

        public bool get_CheckDatasetRows()
        {
            return _BUS.get_CheckDatastRows();
        }

        public bool get_checkRecordCountHQExists()
        {
            bool bolStatus = false;
            try
            {
               bolStatus = _BUS.get_checkRecordCountHQExists();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_checkHQExistsMain"); 
            }
            return bolStatus;
        }

        public bool set_NewCompany()
        {
            bool bolStatus = false;
            try
            {
               bolStatus = _BUS.set_NewCompanyMain();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_NewCompany"); 
            }

            return bolStatus;
        }

        public clsUsersMainBUSInterface()
        {
            _BUS = new clsMainBUS();
           
        }

        public cls_DAL get_DAL
        {
            get
            {
               return  _BUS.get_DAL;
            }
        }

        public DataTable get_AllCompany
        {
            get
            {
                return _BUS.get_AllCompany; 
            }
        }

        public bool set_UpdateAddressBookdt(DataTable dtNew)
        {
            bool bolStatus = false;
            try
            {
               bolStatus = _BUS.set_UpdateAddressBookdt(dtNew);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_UpdateAddressBookdt"); 
            }


            return bolStatus;
        }

        public bool set_UpdateAddressBook(DataRow drUpdate, string strCurrentID)
        {
            bool bolStatus = false;
            try
            {
                bolStatus = _BUS.set_UpdateMain(drUpdate, strCurrentID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_UpdateAddressBook"); 
            }
            return bolStatus;
        }

        public bool set_UpdateMainAddressBook()
        {
            return _BUS.set_UpdateMainAddressBook();
        }

        public DataRow[] get_CompanyDetails(string strCompanyID)
        {
            DataRow[] drDetails = { };
            try
            {
                drDetails = _BUS.get_CompanyDetails(strCompanyID);
            }
            catch (Exception ex)
            {
                MessageBox.Show (ex.Message + " get_CompanyDetails"); 
            }
            return drDetails;
        }
        public void set_InitializeAddressDetails()
        {
            _BUS.set_InitializeAddressDetails();
        }

        public bool set_RejectChangesMain()
        {
            return _BUS.set_RejectChanges();
        }

        public bool set_CompanyDetails(string strCompanyID, string strCompanyType)
        {
            bool bolStatus = false;
            try
            {
                if (_BUS.set_LoadCompanyDetails(strCompanyID.Trim(), strCompanyType) == true)
                {

                    bolStatus = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " clsMainBUSInterface_get_CompanyDetails"); 
            }
            return bolStatus;
        }

        public bool set_AddNewCompany(DataRow drAdd)
        {
             return _BUS.set_AddNewCompany(drAdd); 
        }

        public void Dispose()
        {
            GC.Collect();
           // throw new NotImplementedException();
        }
    }
}
